function delay_branches

% solve: r=-exp(lam*r) where r=A+iB
clf

global lam

figure(1)
% get(gcf)
set(gcf,'Position', [25 1115 658 230])


hold on
%plot([-2*exp(1) -1],[0 0],'b','LineWidth',1.8)
box on
grid on

for ir=1:3

    if ir==1
        N=120; n=1;
    elseif ir==2
        N=780; n=2;
    elseif ir==3
        N=1400; n=3
    end

    lamn=(4*n-3)*pi/2

    AA(1)=0;
    BB(1)=1;

    ep=-0.01;
    B=1+ep*(-lamn)/(1+lamn^2);
    lam=lamn;
    B0=B;
    B1=1.5*B;
    for i=1:N
        lam=lam+ep;
        B=solve(@f,B0,B1);
        AA(i+1)=-B*cos(lam*B)/sin(lam*B);
        BB(i+1)=B;
        if n==2 || n==3
            B0=B; B1=1.5*B;
        elseif n==1
            B0=0; B1=1.2*B;
        end
    end

    if ir==1
        plot(AA,BB,'r','LineWidth',1)
    elseif ir==2
        plot(AA,BB,'b','LineWidth',1)
    elseif ir==3
        plot(AA,BB,'--b','LineWidth',1)
    end
end

%plot(AA,-BB,'b','LineWidth',1.8)
% plot([-exp(1) 0.5],[0 0],'k')
% plot([0 0],[-2 2],'k')
axis([-10 0 0 20])

% set(groot,'defaultAxesTickLabelInterpreter','latex');
% set(gca,'XTick',[-exp(1) -1 0])
% set(gca,'XTickLabel',{'$-e$';'$-1$';'0'})
%
% set(gca,'YTick',[-2 -1 0 1 2])
%set(gca,'YTickLabel',{'$\pi/2$';'$-1$';'0';'$1$';'$\pi/2$'})

% arrowhead([-exp(1)+0.9 -exp(1)+0.85],[0 0],'b',[0.8 1.5],2);
% arrowhead([-exp(1)-1.2 -exp(1)-1.15],[0 0],'b',[0.8 1.5],2);
% ii=30;
% arrowhead([AA(ii) AA(ii+1)],[BB(ii) BB(ii+1)],'b',[0.8 1.5],2);
% arrowhead([AA(ii) AA(ii+1)],[-BB(ii) -BB(ii+1)],'b',[0.8 1.5],2);

set(gca,'FontSize',18,'FontWeight','bold')

xlabel('A','FontSize',16,'FontWeight','bold')
ylabel('B','FontSize',16,'FontWeight','bold')


exportgraphics(gca,'/Users/mark/Desktop/delay.pdf')

function z=f(b)
global lam
A=-b*cos(lam*b)/sin(lam*b);
z=b-exp(-lam*A)*sin(lam*b);

